package org.hongqi.common.senpec.sys.menu;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hongqi.common.senpec.base.mybatisplus.IBaseController;
import org.hongqi.common.senpec.base.sevlet.Result;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RestController
@RequestMapping("/sys/menus")
@RequiredArgsConstructor
@Slf4j
public class MenuController implements IBaseController<Menu> {
    private final MenuService menuService;

    @Override
    public Result<Menu> save(Menu entity) {
        return menuService.mySave(entity);
    }

    @Override
    public Result<?> removeById(Long id) {
        return menuService.myRemoveById(id);
    }

    @Override
    public Result<Menu> updateById(Menu entity) {
        return menuService.myUpdateById(entity);
    }

    @Override
    public Result<Menu> getById(Long id) {
        return menuService.myGetById(id);
    }

    @Override
    public Result<Collection<Menu>> listTree(Menu entity) {
        return menuService.myListTree(entity);
    }

    @GetMapping("/listTreeWithoutButton")
    public Result<Collection<Menu>> listTreeWithoutButton() {
        return menuService.myListTreeWithoutButton();
    }

    @GetMapping("/listMenuButtonsByParentIdAndRoleId/parent/{pid}/role/{rid}")
    public Result<Collection<Menu>> myListMenuButtonsByParentIdAndRoleId(@PathVariable("pid") Long pid, @PathVariable("rid") Long rid) {
        return menuService.myListMenuButtonsByParentIdAndRoleId(pid, rid);
    }

    @GetMapping("/listMenusByRoleId/{roleId}")
    public Result<Collection<Menu>> listMenusByRoleId(@PathVariable("roleId") Long roleId) {
        return menuService.myListMenusByRoleId(roleId);
    }

    @PutMapping("/updateMenuIdsByRoleId")
    public Result<?> updateMenuIdsByRoleId(MenuRoleDTO menuDTO) {
        return menuService.myUpdateMenuIdsByRoleId(menuDTO.getRoleId(), menuDTO.getCurrentMenuId(), menuDTO.getMenuIds());
    }

    @DeleteMapping("/deleteMenuIdsByRoleId/{roleId}")
    public Result<?> deleteMenuIdsByRoleId(@PathVariable("roleId") Long roleId) {
        return menuService.myDeleteMenuIdsByRoleId(roleId);
    }

    @GetMapping("/listMenusForNavy/userId/{userId}")
    public Result<Collection<Menu>> listMenusForNavy(@PathVariable("userId") Long userId) {
        return menuService.myListMenusForNavy(userId);
    }

    @PutMapping("/updateMenuButtonIdByRoleId/role/{roleId}/button/{buttonId}")
    public Result<Menu> updateMenuButtonIdByRoleId(@PathVariable("roleId") Long roleId, @PathVariable("buttonId") Long buttonId) {
        return menuService.myUpdateMenuButtonIdByRoleId(roleId, buttonId);
    }

    @GetMapping("/listMenuButtonIdsByRoleIdAndParent/role/{roleId}/parent/{parentId}")
    public Result<Collection<String>> listMenuButtonIdsByRoleIdAndParent(@PathVariable("roleId") Long roleId, @PathVariable("parentId") Long parentId) {
        return menuService.myListMenuButtonIdsByRoleIdAndParent(roleId, parentId);
    }

    @PutMapping("/updateMenuSequence/menu/{id}/direction/{direction}")
    public Result<Menu> updateMenuSequence(@PathVariable("id") Long id, @PathVariable("direction") String direction) {
        return menuService.myUpdateMenuSequence(id, direction);
    }

    @GetMapping("/listAuthoritiesByUserId/user/{id}")
    public Result<Collection<String>> listAuthoritiesByUserId(@PathVariable("id") Long id) {
        return menuService.myListAuthoritiesByUserId(id);
    }

}
